import pandas as pd
from sklearn import model_selection
import numpy as np
import dt

df = pd.read_csv('C:\Home\Shu\大三冬\machine-learning\ml\data\watermelon-3.0.csv')

#处理连续值
for i in range(len(df['密度'])):
    if float(df['密度'][i]) > 0.381:
        df['密度'][i] = "大"
    else:
        df['密度'][i] = "小"

for i in range(len(df['含糖率'])):
    if float(df['含糖率'][i]) > 0.126:
        df['含糖率'][i] = "高"
    else:
        df['含糖率'][i] = "低"

print(df)
features = np.array(['色泽','根蒂','敲声','纹理','脐部','触感','密度','含糖率'])

samples = df[features].to_numpy()
labels = df[['好瓜']].to_numpy().squeeze()

#x_train, x_test, y_train, y_test = model_selection.train_test_split(samples, labels, test_size=0.25, random_state=0)


tree = dt.DecisionTree()
tree.fit(samples, labels, features)

tree.view()